# -*- coding: utf-8 -*-
# @Time    : 2020/5/3 8:50
# @Author  : weymouth
# @Email   : 261229090@qq.com
# @File    : 反射.py
# @Software: PyCharm
#---------------------------------------------------

# class Foo:
#     def __init__(self, n, a):
#         self.name = n
#         self.age = a
#
#     def show(self):
#         return "%s - %s" % (self.name, self.age)
#
# #通过字符串的形式操作对象中的成员
# obj = Foo('abc', 18)
# '''去什么里取什么东西，getattr'''
# func = getattr(obj, 'show')
# print(func)
# r = func()
# print(r)
#
# '''检查是否存在，hasattr'''
# print(hasattr(obj, 'name'))
#
# '''设置新值,setattr'''
# setattr(obj, 'k1', 'v1')
# print(obj.k1)
#
# '''删除，delattr'''
# delattr(obj, 'name')

# obj.name
# b = 'name'
# obj.b

# b = "name"
# f = obj.__dict__["name"]
# g = obj.__dict__[b]
# print(f)
# print(g)
#
# inp = input('>>>')
# v = getattr(obj, inp)
# print(v)